<template>
  <div class="card">
    <!--上传毕业证-->
    <div class="upload-card">
      <div class="upload-card-title">毕业证</div>
      <van-uploader class="upload" :after-read="uploadImg">
        <div class="IDcard-front">
          <img class="IDcard-front-img" :src="graduation_image" />
          <img
            class="upload-button"
            v-if="!graduation_image || graduation_image.indexOf('http') === -1"
            src="@/static/add.png"
          />
        </div>
      </van-uploader>
    </div>
    <div class="example">
      <div class="example-title">证件上传示例</div>
      <div class="example-wrapper">
        <div class="example-item">
          <img src="@/static/icon_IDcard_right@2x.png" />
          <div class="example-item-title">标准</div>
        </div>
        <div class="example-item">
          <img src="@/static/icon_IDcard_quebian@2x.png" />
          <div class="example-item-title">缺边</div>
        </div>
        <div class="example-item">
          <img src="@/static/icon_IDcard_mohu@2x.png" />
          <div class="example-item-title">模糊</div>
        </div>
        <div class="example-item">
          <img src="@/static/icon_IDcard_flash@2x.png" />
          <div class="example-item-title">闪光</div>
        </div>
      </div>
    </div>
    <button
      @click="goNext"
      :class="`button ${graduation_image ? 'green-button' : ''}`"
      size="mini"
    >
      提交
    </button>
    <div v-if="time" class="mask"></div>
    <div v-if="time" class="model">
      <div class="model-title">错误示例</div>
      <div class="time">{{ time }} s</div>
      <div class="model-item-wrapper">
        <div class="model-item">
          <img src="@/static/book_quebian@2x.png" />
          <div class="model-item-desc">
            <img src="@/static/×@2x.png" />
            <div>缺边</div>
          </div>
        </div>
        <div class="model-item">
          <img src="@/static/book_quebian2@2x.png" />
          <div class="model-item-desc">
            <img src="@/static/×@2x.png" />
            <div>缺边</div>
          </div>
        </div>
        <div class="model-item">
          <img src="@/static/book_mohu@2x.png" />
          <div class="model-item-desc">
            <img src="@/static/×@2x.png" />
            <div>模糊</div>
          </div>
        </div>
        <div class="model-item">
          <img src="@/static/book_flash@2x.png" />
          <div class="model-item-desc">
            <img src="@/static/×@2x.png" />
            <div>闪光</div>
          </div>
        </div>
      </div>
    </div>
    <div class="nav" @click="$router.go(-1)">返回</div>
  </div>
</template>

<script>
import graduation_image from "@/static/idcard_front.png";
export default {
  data() {
    return {
      graduation_image,
      setIntervalId: null,
      time: 3,
      fileList: []
    };
  },
  mounted() {
    const setIntervalId = setInterval(() => {
      this.time--;

      if (this.time <= 0) {
        clearInterval(setIntervalId);
        this.setIntervalId = null;
      }
    }, 1000);
    this.setIntervalId = setIntervalId;
  },
  methods: {
    /**
     * @author 黎明霞光 2021-05-18
     * 读取完图片后
     * file 选取的文件对象
     **/
    uploadImg(file) {
      console.log(file);
      // this.fileList = [{ ...file }];
      // TODO: 请求接口后赋值
      // 下面的是写死的
      this.graduation_image =
        "https://www.baidu.com/img/flexible/logo/pc/result.png";
    },
    /**
     * @author 鲁佳明 2021-05-18
     * 提交保存
     */
    goNext() {
      // TODO: 提交保存
    }
  },
  beforeDestroy() {
    clearInterval(this.setIntervalId);
    this.setIntervalId = null;
  }
};
</script>

<style lang="less" scoped>
.card {
  height: 100vh;
  background-color: #f1f1f1;
  box-sizing: border-box;
  padding-bottom: 0.1rem;
  overflow: hidden;
}
.upload-card {
  width: 100%;
  height: 5rem;
  background: #ffffff;
  // margin-top: 0.17rem;
  overflow: hidden;
}
.upload {
  display: block;
  width: 4.21rem;
  margin: 0.3rem auto 0.42rem;
}
.upload-card .IDcard-front {
  display: block;
  position: relative;
  width: 4.21rem;
  height: 2.85rem;
  margin: 0.3rem auto 0.42rem;
}

.IDcard-front .IDcard-front-img {
  display: block;
  width: 100%;
  height: 100%;
}

.upload-card .upload-card-title {
  font-size: 0.24rem;
  color: #73a1ff;
  margin-left: 0.41rem;
  margin-top: 0.2rem;
}

.upload-card .upload-button {
  box-sizing: border-box;
  width: 1.2rem;
  height: 1.2rem;
  background: #73a1ff;
  border-radius: 50%;
  padding: 0.2rem;
  position: absolute;
  left: calc(50% - 0.6rem);
  top: calc(50% - 0.6rem);
}

.example .example-title {
  font-size: 0.28rem;
  font-weight: bold;
  color: #73a1ff;
  margin-top: 0.32rem;
  margin-left: 0.32rem;
  margin-bottom: 0.23rem;
}

.example .example-item img {
  display: block;
  width: 1.32rem;
  height: 0.94rem;
}

.example-wrapper {
  width: 6.84rem;
  display: flex;
  margin-left: auto;
  margin-right: auto;
  justify-content: space-between;
}

.example-item-title {
  width: 1.32rem;
  height: 0.5rem;
  background: #cccccc;
  border-radius: 0 0 0.1rem 0.1rem;
  text-align: center;
  line-height: 0.5rem;
  font-size: 0.28rem;
}

.button {
  display: block;
  width: 3rem;
  height: 0.64rem;
  margin: 0.99rem auto 0.99rem;
  border-radius: 0.1rem;
  font-size: 0.28rem;
  border: none !important;
  background: #dddddd;
  color: #999999;
}

.green-button {
  background: #07c160;
  color: #fff;
}

.mask {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  height: 100%;
  background: #000000;
  opacity: 0.5;
  z-index: 98;
}

.model {
  position: fixed;
  top: 1.1rem;
  left: calc(50% - 3.43rem);
  width: 6.86rem;
  height: 6.96rem;
  background: #f1f1f1;
  z-index: 99;
}

.model .model-title {
  font-size: 0.32rem;
  font-weight: bold;
  color: #73a1ff;
  text-align: center;
  margin-top: 0.2rem;
  margin-bottom: 0.4rem;
}

.model .time {
  position: absolute;
  top: 0.2rem;
  right: 0.5rem;
  color: #666;
  font-size: 0.32rem;
}

.model-item-wrapper {
  width: 6.26rem;
  margin-left: auto;
  margin-right: auto;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
}

.model-item {
  margin-bottom: 0.3rem;
}

.model-item > img {
  display: block;
  width: 2.86rem;
  height: 2.1rem;
}

.model-item-desc {
  display: flex;
  align-items: center;
  margin-left: 0.74rem;
  font-size: 0.24rem;
  color: #666;
  margin-top: 0.15rem;
}

.model-item-desc img {
  width: 0.4rem;
  height: 0.4rem;
  margin-right: 0.15rem;
}
.nav {
  position: fixed;
  bottom: 35%;
  right: 0;
  border-radius: 0.15rem 0 0 0.15rem;
  width: 1rem;
  height: 1rem;
  line-height: 1rem;
  text-align: center;
  background-color: #78a4ff;
  color: #fff;
  font-size: 0.26rem;
}
</style>
